import {
  reqCategoryListData,
  reqBannerListDate,
  reqGetFloorsListData,
} from '../../api';

const state = {
  categoryList: [],
  bannerList: [],
  floorsList: [],
};

const actions = {
  //1、获取第三级分数数据
  async getCategoryListData({ commit }) {
    const result = await reqCategoryListData();
    //判断获取的数据是否成功
    if (result.code === 200) {
      commit('SAVE_CATEGORY_LIST_DATA', result.data);
    }
  },
  async getBannerListData({ commit }) {
    const result = await reqBannerListDate();

    //判断获取的数据是否成功
    if (result.code === 200) {
      commit('SAVE_BANNER_LIST_DATA', result.data);
    }
  },
  async getFloorsListData({ commit }) {
    const result = await reqGetFloorsListData();
    if (result.code === 200) {
      commit('SAVE_FLOORS_LIST_DATA', result.data);
    }
  },
}; //异步程序都是放在这里的
const mutations = {
  SAVE_CATEGORY_LIST_DATA(state, payload) {
    state.categoryList = payload;
  },
  SAVE_BANNER_LIST_DATA(state, payload) {
    state.bannerList = payload;
  },
  // 3.楼层数据
  SAVE_FLOORS_LIST_DATA(state, floorsList) {
    state.floorsList = floorsList;
  },
};

const getters = {};
//4、创建实例和导出

export default {
  namespaced: true, //分模块开发，一定要留命名空间
  state,
  actions,
  getters,
  mutations,
};
